﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="ibox-content">
    <form class="form form-horizontal" id="form" autocomplete="off">
        <input type="hidden" name="id" id="id" value="@(ViewBag.Id)">
        <div class="form-group">
            <label class="col-sm-3 control-label">角色名称：</label>
            <div class="col-sm-4">
                <input type="text" name="role_name" id="role_name" value="" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">角色编码：</label>
            <div class="col-sm-4">
                <input type="text" name="role_code" id="role_code" value="" class="form-control" data-rule="required">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label required">排序：</label>
            <div class="col-sm-4">
                <input type="text" name="sort" id="sort" class="form-control" data-rule="required;integer; range[1~1000]">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-9">
                <textarea name="remark" id="remark" cols="60" rows="4"></textarea>
            </div>
        </div>
        <div class="hr-line-dashed"></div>
        <div class="form-group">
            <div class="col-sm-12 col-sm-offset-3">
                <button class="btn btn-primary" type="submit">保存内容</button>
                <button class="btn btn-white" type="button" onclick="cancel()">取消</button>
            </div>
        </div>
    </form>
</div>

    @section scripts{
        <script type="text/javascript">
            var index = parent.layer.getFrameIndex(window.name);
            $(function () {
                $('#form').validator({
                    stopOnError: false,
                    timely: 2,
                    theme: "yellow_right",
                    valid: function (form) {
                        // 表单验证通过，提交表单
                        jutils.ajaxPost('/admin/sysrole/savedata', $(form).serialize(),
                            function (res) {
                                parent.layer.close(index);
                            });
                    }
                });

                loadData();
            });


            function loadData() {
                var id = $("#id").val();

                if (id !== '') {
                    jutils.ajaxGet('/admin/sysrole/GetRoleByIds', { id: id }, function (res) {
                        $('#form').initFormData(res.data.model);

                    });
                }
            }


            function cancel() {
                parent.layer.close(index);
            }
        </script>


    }



